import pymysql

conn=None
cursor=None
try:
    conn = pymysql.connect(user="root",
                           password='hhf20101',
                           host='localhost',
                           database='books',
                           autocommit=False)
    cursor = conn.cursor()
    sql = "insert into t_book(id, title, pub_date) values(4, '西游记', '1986-01-01');"
    sql1 = "insert into t_book(id, title, pub_date) values(5, '西游记', '1986-01-01');"
    cursor.execute(sql)
    print(cursor.rowcount)
    raise Exception('程序出错了，哈哈哈')
    cursor.execute(sql1)
    print(cursor.rowcount)
    conn.commit()
except Exception as e:
    conn.commit()
finally:
    cursor.close()
    conn.close()

